namespace SubhadraSolutions.Sharp.Logging.LogItems
{
    using SubhadraSolutions.Sharp.Utils.Reflection;
    using System;

    [Serializable]
    public class SimpleLogItem
    {
        #region Constructors

        public SimpleLogItem(string message, Exception exception)
            : this(message, exception, DefaultSourceName)
        {
        }

        public SimpleLogItem(string message, Exception exception, string sourceName)
        {
            Message = message;
            Exception = exception;
            SourceName = sourceName;
        }

        #endregion Constructors

        #region Properties

        public static string DefaultSourceName
        {
            get;
            set;
        }

        [PropertyOrder(3)]
        public Exception Exception
        {
            get;
            private set;
        }

        [PropertyOrder(1)]
        public string Message
        {
            get;
            private set;
        }

        [PropertyOrder(0)]
        public string SourceName
        {
            get;
            private set;
        }

        #endregion Properties

        #region Methods

        public static SimpleLogItem CreateNew(string message, Exception exception)
        {
            return new SimpleLogItem(message, exception);
        }

        public static SimpleLogItem CreateNew(string message, Exception exception,
            string sourceName)
        {
            return new SimpleLogItem(message, exception, sourceName);
        }

        public override string ToString()
        {
            string s = DynamicToStringHelper<SimpleLogItem>.ExportAsString(this,
                delegate(string propertyName, object propertyValue, bool isLastProperty)
                {
                    string returnValue = string.Format("{0}={1}{2}", propertyName, propertyValue,
                        isLastProperty ? "\r\n" : ",");
                    return returnValue;
                });
            return s;
        }

        #endregion Methods
    }
}